#include "StdAfx.h"
#include "RevenueRepoMySQL.h"
#include "POSManager.h"

CRevenueRepoMySQL::CRevenueRepoMySQL(void)
{
}

CRevenueRepoMySQL::~CRevenueRepoMySQL(void)
{
}
BOOL CRevenueRepoMySQL::UpdateAllRecord(CList<CRevenueAccount, CRevenueAccount&> * pAccountList, UINT searchPeriod)
{
	CPOSManagerApp* pApp;
	pApp = (CPOSManagerApp*)::AfxGetApp();

	resultset = pApp->sqlConnector.LookUpRevenueRecord(pAccountList, searchPeriod);

	if(resultset == NULL)
		return FALSE;
	try
	{
		resultset->first();
		
		pAccountList->RemoveAll();
	
		while(resultset->isAfterLast() == FALSE)
		{
			CRevenueAccount TransactionTmp;
			TransactionTmp.AcountType = resultset->getInt("transactiontype");
			TransactionTmp.AmountOfMoney = resultset->getInt("money");
			TransactionTmp.Memo = pApp->sqlConnector.UTF8ToUnicode(resultset->getString("memo").c_str());
			TransactionTmp.TransActionDate.ParseDateTime(pApp->sqlConnector.UTF8ToUnicode(resultset->getString("transactiondate").c_str()));
			TransactionTmp.Name = pApp->sqlConnector.UTF8ToUnicode(resultset->getString("name").c_str());
			pAccountList->AddTail(TransactionTmp);
			resultset->next();
		}
	}
	catch(sql::SQLException &e)
	{
		CString errStr = _T("");
		errStr.Format(_T("Error : %s\nError Code. : %d"), pApp->sqlConnector.UTF8ToUnicode(e.what()), e.getErrorCode());
		::AfxMessageBox(errStr, MB_OK | MB_ICONSTOP, NULL);
		return FALSE;
	}

	delete resultset;
	return TRUE;
}